package com.neusoft.javafxdemo2.common;

import com.neusoft.javafxdemo2.SupervisorLogin;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;

public class AlertUtils {
    public static void showDialog(String title,String content){
        Alert dialog = new Alert(Alert.AlertType.INFORMATION);
        dialog.setTitle(title);
        dialog.setHeaderText(null);
        dialog.setContentText(content);
        dialog.showAndWait();
    }
    //方法重写：发生在继承的时候，子类重写父类的方法
    public static void switchToView(Parent node,String fxmlFileName){
        //跳转到注册界面
        FXMLLoader fxmlLoader = new FXMLLoader();
        URL url = SupervisorLogin.class.getResource(fxmlFileName);
        fxmlLoader.setLocation(url);
        Parent root = null;
        try {
            root = fxmlLoader.load();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Scene scene = new Scene(root);
        //Stage(我们不创建新的窗体）
        Stage stage = (Stage) node.getScene().getWindow();
        stage.setScene(scene);
        stage.show();
    }
    //方法重载，同名不同参数
    public static void switchToView(Parent node,String fxmlFileName,int width,int height){
        //跳转到注册界面
        FXMLLoader fxmlLoader = new FXMLLoader();
        URL url = SupervisorLogin.class.getResource(fxmlFileName);
        fxmlLoader.setLocation(url);
        Parent root = null;
        try {
            root = fxmlLoader.load();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Scene scene = new Scene(root);
        //Stage(我们不创建新的窗体）
        Stage stage = (Stage) node.getScene().getWindow();
        stage.setScene(scene);
        //设置打开窗口的宽度和高度
        stage.setWidth(width);
        stage.setHeight(height);
        stage.show();
    }
}
